<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>煤炭管理系统</title>
    <link rel="stylesheet" href="/static/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/lib/layui/css/layui-theme-custom.css">
    <link rel="stylesheet" href="/static/css/member.css">
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <#include "/base/main-header.ftl">

    <#include "/base/main-left.ftl">
    <div class="layui-body">
        <!-- 内容主体区域  -->
        <div class="site-title">
            <fieldset>
                <legend>
                    <a class="site-title-text">公告列表</a>
                </legend>
            </fieldset>
        </div>
        <div  class="table-box">

            <div class="site-text site-block">
                <form action="" class="layui-form">
                    <div class="layui-form-item">
                        <label   class="myLable">公告状态：</label>
                        <div class="layui-input-block">
                            <input type="radio" name="status" value="" title="全部" checked="">
                            <input type="radio" name="status" value="0" title="草稿">
                            <input type="radio" name="status" value="1" title="已发布">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <button id="query-btn" class="layui-btn layui-btn-radius layui-inline">查询</button>
                        </div>
                    </div>
                </form>
            </div>
            <table class="layui-hide" id="queryAnnoc" lay-filter="AnnocTable"></table>
        </div>


    </div>
    <#include "/base/main-footer.ftl">
</div>

<script src="/static/lib/layui/layui.js"></script>
<script type="text/html" id="annoStatus">
<span>
    {{#  if(d.annocStatus == 0 ){ }}
     草稿
      {{#  } else { }}
    已发布
    {{#  } }}
</span>
</script>
<script type="text/html" id="operator">
    <button class="layui-btn layui-btn-xs" lay-event="edit">修改</button>
    <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>
    <button class="layui-btn layui-btn-xs" lay-event="detail">查看</button>
</script>
<script>
    layui.use(['layer', 'form', 'element', 'jquery','table'], function () {
        let layer = layui.layer, form = layui.form, $ = layui.$, table = layui.table;
        let pe = table.render({
            elem: '#queryAnnoc',
            url:'/annoc/list',
            method: 'post',
            contentType: 'application/json',
            cols: [[
                {field:'id',title: '序号', width:100, sort: true}
                ,{field:'title',  title: '标题', width:350}
                ,{field:'createTime',  title: '创建时间', sort: true }
                ,{field:'author', title: '作者'}
                ,{field:'annocStatus', title: '状态',templet: '#annoStatus'}
                ,{field:'', title: '操作',templet: '#operator', unresize: true}
            ]],
            page: true,
            parseData: function(res){
                return {
                    "code": res.code,
                    "msg": res.msg,
                    "count": res.data.total,
                    "data": res.data.rows
                };
            }
        })
        $("#query-btn").click(function (ele) {
            pe.reload({
                where:{
                    status: parseInt($("input[name='status']:checked").val()),
                }
            })
            return false
        })
        table.on('tool(AnnocTable)', function(obj){
            var data = obj.data;
            var layEvent = obj.event;
            var tr = obj.tr;

            if(layEvent === 'detail'){ //查看
                window.location = '/annoc/'+data.id
            } else if(layEvent === 'del'){ //删除
                layer.confirm('真的删除这条记录吗？', function(index){
                    obj.del();
                    layer.close(index);
                    $.ajax({
                        type: "POST",
                        url: "/annoc/removeById?id="+data.id,
                        success: function (data) {
                            if (data.isSuccess){
                                layer.msg("删除成功")
                            } else {
                                layer.msg(data.msg)
                            }
                        }
                    });
                });
            } else if(layEvent === 'edit'){ //编辑
                window.location = '/announc/add?id='+data.id

            }
        });
    });
</script>
</body>
</html>